#coding=utf-8
#Boa:FramePanel:PanelMallDailyStat

import wx
from MyListCtrl import *

[wxID_PANELMALLDAILYSTAT, wxID_PANELMALLDAILYSTATBTNALLDATE, 
 wxID_PANELMALLDAILYSTATBTNCATEGORY, wxID_PANELMALLDAILYSTATBTNCUSTOMER, 
 wxID_PANELMALLDAILYSTATBTNDAYAFTER, wxID_PANELMALLDAILYSTATBTNDAYBEFORE, 
 wxID_PANELMALLDAILYSTATBTNONEDAY, wxID_PANELMALLDAILYSTATBTNONEMONTH, 
 wxID_PANELMALLDAILYSTATBTNONEWEEK, wxID_PANELMALLDAILYSTATBTNONEYEAR, 
 wxID_PANELMALLDAILYSTATBTNPRODUCT, wxID_PANELMALLDAILYSTATBTNREGION, 
 wxID_PANELMALLDAILYSTATBTNSTAFF, wxID_PANELMALLDAILYSTATBTNTOTAL, 
 wxID_PANELMALLDAILYSTATDATEEND, wxID_PANELMALLDAILYSTATDATESTART, 
 wxID_PANELMALLDAILYSTATSTATICTEXT1, wxID_PANELMALLDAILYSTATTDATE, 
] = [wx.NewId() for _init_ctrls in range(18)]

class PanelMallDailyStat(wx.Panel):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Panel.__init__(self, id=wxID_PANELMALLDAILYSTAT,
              name=u'PanelMallDailyStat', parent=prnt, pos=wx.Point(424, 183),
              size=wx.Size(1145, 710), style=wx.TAB_TRAVERSAL)
        self.SetClientSize(wx.Size(1129, 672))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Arial'))
        self.SetBackgroundColour(wx.Colour(183, 209, 173))

        self.TDate = wx.StaticText(id=wxID_PANELMALLDAILYSTATTDATE,
              label=u'\u5355\u636e\u65e5\u671f\uff1a', name=u'TDate',
              parent=self, pos=wx.Point(22, 38), size=wx.Size(85, 19), style=0)
        self.TDate.SetAutoLayout(True)
        self.TDate.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'Arial'))

        self.dateStart = wx.DatePickerCtrl(id=wxID_PANELMALLDAILYSTATDATESTART,
              name=u'dateStart', parent=self, pos=wx.Point(126, 30),
              size=wx.Size(120, 27), style=wx.DP_DROPDOWN)
        self.dateStart.SetLabel(u'2014-04-24')
        self.dateStart.SetValue(wx.DateTimeFromDMY(24, 3, 2014, 0, 0, 0))
        self.dateStart.SetToolTipString(u'dateStart')

        self.dateEnd = wx.DatePickerCtrl(id=wxID_PANELMALLDAILYSTATDATEEND,
              name=u'dateEnd', parent=self, pos=wx.Point(278, 30),
              size=wx.Size(116, 27), style=wx.DP_DROPDOWN)

        self.staticText1 = wx.StaticText(id=wxID_PANELMALLDAILYSTATSTATICTEXT1,
              label=u'\u81f3', name='staticText1', parent=self,
              pos=wx.Point(254, 38), size=wx.Size(18, 18), style=0)

        self.btnOneDay = wx.Button(id=wxID_PANELMALLDAILYSTATBTNONEDAY,
              label=u'\u5f53\u65e5', name=u'btnOneDay', parent=self,
              pos=wx.Point(402, 30), size=wx.Size(46, 29), style=0)
        self.btnOneDay.Bind(wx.EVT_BUTTON, self.OnBtnOneDayButton,
              id=wxID_PANELMALLDAILYSTATBTNONEDAY)

        self.btnOneWeek = wx.Button(id=wxID_PANELMALLDAILYSTATBTNONEWEEK,
              label=u'\u4e00\u5468', name=u'btnOneWeek', parent=self,
              pos=wx.Point(450, 30), size=wx.Size(46, 29), style=0)
        self.btnOneWeek.Bind(wx.EVT_BUTTON, self.OnBtnOneWeekButton,
              id=wxID_PANELMALLDAILYSTATBTNONEWEEK)

        self.btnOneMonth = wx.Button(id=wxID_PANELMALLDAILYSTATBTNONEMONTH,
              label=u'\u4e00\u6708', name=u'btnOneMonth', parent=self,
              pos=wx.Point(498, 30), size=wx.Size(46, 29), style=0)
        self.btnOneMonth.Bind(wx.EVT_BUTTON, self.OnBtnOneMonthButton,
              id=wxID_PANELMALLDAILYSTATBTNONEMONTH)

        self.btnOneYear = wx.Button(id=wxID_PANELMALLDAILYSTATBTNONEYEAR,
              label=u'\u4e00\u5e74', name=u'btnOneYear', parent=self,
              pos=wx.Point(546, 30), size=wx.Size(46, 29), style=0)
        self.btnOneYear.Bind(wx.EVT_BUTTON, self.OnBtnOneYearButton,
              id=wxID_PANELMALLDAILYSTATBTNONEYEAR)

        self.btnAllDate = wx.Button(id=wxID_PANELMALLDAILYSTATBTNALLDATE,
              label=u'\u5168\u90e8', name=u'btnAllDate', parent=self,
              pos=wx.Point(594, 30), size=wx.Size(46, 29), style=0)
        self.btnAllDate.Bind(wx.EVT_BUTTON, self.OnBtnAllDateButton,
              id=wxID_PANELMALLDAILYSTATBTNALLDATE)

        self.btnDayBefore = wx.Button(id=wxID_PANELMALLDAILYSTATBTNDAYBEFORE,
              label=u'\u524d\u4e00\u5929', name=u'btnDayBefore', parent=self,
              pos=wx.Point(656, 30), size=wx.Size(64, 29), style=0)
        self.btnDayBefore.Bind(wx.EVT_BUTTON, self.OnBtnDayBeforeButton,
              id=wxID_PANELMALLDAILYSTATBTNDAYBEFORE)

        self.btnDayAfter = wx.Button(id=wxID_PANELMALLDAILYSTATBTNDAYAFTER,
              label=u'\u540e\u4e00\u5929', name=u'btnDayAfter', parent=self,
              pos=wx.Point(720, 30), size=wx.Size(64, 29), style=0)
        self.btnDayAfter.Bind(wx.EVT_BUTTON, self.OnBtnDayAfterButton,
              id=wxID_PANELMALLDAILYSTATBTNDAYAFTER)

        self.btnTotal = wx.Button(id=wxID_PANELMALLDAILYSTATBTNTOTAL,
              label=u'\u65e5\u9500\u552e', name=u'btnTotal', parent=self,
              pos=wx.Point(24, 64), size=wx.Size(86, 29), style=0)
        self.btnTotal.Bind(wx.EVT_BUTTON, self.OnBtnTotalButton,
              id=wxID_PANELMALLDAILYSTATBTNTOTAL)

        self.btnStaff = wx.Button(id=wxID_PANELMALLDAILYSTATBTNSTAFF,
              label=u'\u4e1a\u52a1\u5458', name=u'btnStaff', parent=self,
              pos=wx.Point(336, 64), size=wx.Size(86, 29), style=0)
        self.btnStaff.Bind(wx.EVT_BUTTON, self.OnBtnStaffButton,
              id=wxID_PANELMALLDAILYSTATBTNSTAFF)

        self.btnCategory = wx.Button(id=wxID_PANELMALLDAILYSTATBTNCATEGORY,
              label=u'\u5206\u7c7b\u9500\u552e', name=u'btnCategory',
              parent=self, pos=wx.Point(544, 64), size=wx.Size(86, 29),
              style=0)
        self.btnCategory.Bind(wx.EVT_BUTTON, self.OnBtnCategoryButton,
              id=wxID_PANELMALLDAILYSTATBTNCATEGORY)

        self.btnProduct = wx.Button(id=wxID_PANELMALLDAILYSTATBTNPRODUCT,
              label=u'\u4ea7\u54c1\u9500\u552e', name=u'btnProduct',
              parent=self, pos=wx.Point(440, 64), size=wx.Size(86, 29),
              style=0)
        self.btnProduct.Bind(wx.EVT_BUTTON, self.OnBtnProductButton,
              id=wxID_PANELMALLDAILYSTATBTNPRODUCT)

        self.btnCustomer = wx.Button(id=wxID_PANELMALLDAILYSTATBTNCUSTOMER,
              label=u'\u5ba2\u6237', name=u'btnCustomer', parent=self,
              pos=wx.Point(128, 64), size=wx.Size(86, 29), style=0)
        self.btnCustomer.Bind(wx.EVT_BUTTON, self.OnBtnCustomerButton,
              id=wxID_PANELMALLDAILYSTATBTNCUSTOMER)

        self.btnRegion = wx.Button(id=wxID_PANELMALLDAILYSTATBTNREGION,
              label=u'\u533a\u57df\u7edf\u8ba1', name=u'btnRegion', parent=self,
              pos=wx.Point(232, 64), size=wx.Size(86, 29), style=0)
        self.btnRegion.Bind(wx.EVT_BUTTON, self.OnBtnRegionButton,
              id=wxID_PANELMALLDAILYSTATBTNREGION)

    def __init__(self, parent):
        self._init_ctrls(parent)

        self.dateStart.SetValue(wx.DateTime.Today())
        self.dateEnd.SetValue(wx.DateTime.Today())      
                        
        self.lcDay = MyListCtrlSaleDayMall(self)
        self.lcDay.SetSize(wx.Size(1200, 600))
        self.lcDay.Move(wx.Point(22,100))
        #self.lcDay.Show(False)
        
        self.lcCust = MyListCtrlSaleCustomerMall(self)
        self.lcCust.SetSize(wx.Size(1200, 600))
        self.lcCust.Move(wx.Point(22,100))
        self.lcCust.Show(False)
        
##        self.lcCustType = MyListCtrlSaleCustomerTypeReport(self)
##        self.lcCustType.SetSize(wx.Size(900, 600))
##        self.lcCustType.Move(wx.Point(22,100))
##        self.lcCustType.Show(False)
        
        self.lcCustRegion = MyListCtrlSaleCustomerRegionMall(self)
        self.lcCustRegion.SetSize(wx.Size(1200, 600))
        self.lcCustRegion.Move(wx.Point(22,100))
        self.lcCustRegion.Show(False)
        
        self.lcStaff = MyListCtrlSaleStaffMall(self)
        self.lcStaff.SetSize(wx.Size(1200, 600))
        self.lcStaff.Move(wx.Point(22,100))
        self.lcStaff.Show(False)
        
##        self.lcDelivery = MyListCtrlSaleDeliveryReport(self)
##        self.lcDelivery.SetSize(wx.Size(900, 600))
##        self.lcDelivery.Move(wx.Point(22,100))
##        self.lcDelivery.Show(False)
        
        self.lcProduct = MyListCtrlSaleProductMall(self)
        self.lcProduct.SetSize(wx.Size(1200, 560))
        self.lcProduct.Move(wx.Point(22,100))
        self.lcProduct.Show(False)
        
        self.lcCategory = MyListCtrlSaleCategoryMall(self)
        self.lcCategory.SetSize(wx.Size(1200, 560))
        self.lcCategory.Move(wx.Point(22,100))
        self.lcCategory.Show(False)
        
##        self.lcSupplier = MyListCtrlSaleSupplierReport(self)
##        self.lcSupplier.SetSize(wx.Size(900, 600))
##        self.lcSupplier.Move(wx.Point(22,100))
##        self.lcSupplier.Show(False)
        
##        self.queryType = {'daySale':u'每日销售统计',
##                            'customer':u'客户销售统计',
##                            'custType':u'客户类型统计',
##                            'custRegion':u'区域销售统计',
##                            'staff':u'业务员销售统计',
##                            'delivery':u'配送方式统计',
##                            'product':u'产品销售统计',
##                            'category':u'分类销售统计',
##                            'supplier':u'供货商统计'}
##        for type,label in self.queryType.items():
##            self.cbQuery.Append(label, type)
        
        self.queryLc = {'daySale':self.lcDay,
                            'customer':self.lcCust,
                            #'custType':self.lcCustType,
                            'custRegion':self.lcCustRegion,
                            'staff':self.lcStaff,
                            #'delivery':self.lcDelivery,
                            'product':self.lcProduct,
                            'category':self.lcCategory,
                            #'supplier':self.lcSupplier
                        }
                                
        #self.cbQuery.SetValue(u'每日销售统计')
        self.lc = self.lcDay
        #self.lc.Show()

    def OnBtnOneDayButton(self, event):
        self.dateStart.SetValue(wx.DateTime.Today())
        self.dateEnd.SetValue(wx.DateTime.Today())

    def OnBtnOneWeekButton(self, event):
        day = wx.DateTime.Today()
        self.dateEnd.SetValue(day)
        
        span = wx.DateSpan.Days(7)
        day.SubtractDS(span)
        self.dateStart.SetValue(day)
        

    def OnBtnOneMonthButton(self, event):
        day = wx.DateTime.Today()
        self.dateEnd.SetValue(day)
        
        span = wx.DateSpan.Months(1)
        day.SubtractDS(span)
        self.dateStart.SetValue(day)

    def OnBtnOneYearButton(self, event):
        day = wx.DateTime.Today()
        self.dateEnd.SetValue(day)
        
        span = wx.DateSpan.Years(1)
        day.SubtractDS(span)
        self.dateStart.SetValue(day)

    def OnBtnAllDateButton(self, event):
        self.dateEnd.SetValue(wx.DateTime.Today())        
        self.dateStart.SetValue(wx.DateTimeFromDMY(1,0,2000,0,0,00))

    def OnBtnDayBeforeButton(self, event):
        day = self.dateEnd.GetValue()        
        span = wx.DateSpan.Days(1)
        day.SubtractDS(span)
        self.dateEnd.SetValue(day)
        self.dateStart.SetValue(day)

    def OnBtnDayAfterButton(self, event):
        day = self.dateEnd.GetValue()        
        span = wx.DateSpan.Days(1)
        day.AddDS(span)
        self.dateEnd.SetValue(day)
        self.dateStart.SetValue(day)

    def OnBtnSearchButton(self, event):
        filter = {'dateStart':self.dateStart.GetValue().Format('%Y-%m-%d'),
                    'dateEnd':self.dateEnd.GetValue().Format('%Y-%m-%d')}
        
        self.lc.Show(False)
        self.lc = self.queryLc[self.cbQuery.GetClientData(self.cbQuery.GetSelection())]
        self.lc.Show()
        
        cnt = self.lc.refresh(filter)
        if (cnt == 0):
            dlg = wx.MessageDialog(self, u'没有符合条件的记录', u'提示消息', wx.OK|wx.ICON_INFORMATION)
            dlg.ShowModal()

    def refresh_list(self, type):
        filter = {'dateStart':self.dateStart.GetValue().Format('%Y-%m-%d'),
                    'dateEnd':self.dateEnd.GetValue().Format('%Y-%m-%d')}
        
        self.lc.Show(False)
        self.lc = self.queryLc[type]
        self.lc.Show()
        
        cnt = self.lc.refresh(filter)
        if (cnt == 0):
            dlg = wx.MessageDialog(self, u'没有符合条件的记录', u'提示消息', wx.OK|wx.ICON_INFORMATION)
            dlg.ShowModal()
        
    def OnBtnTotalButton(self, event):
        self.refresh_list('daySale')

    def OnBtnCustomerButton(self, event):
        self.refresh_list('customer')

    def OnBtnCustTypeButton(self, event):
        self.refresh_list('custType')

    def OnBtnRegionButton(self, event):
        self.refresh_list('custRegion')

    def OnBtnStaffButton(self, event):
        self.refresh_list('staff')

    def OnBtnDeliveryButton(self, event):
        self.refresh_list('delivery')
        
    def OnBtnProductButton(self, event):
        self.refresh_list('product')

    def OnBtnCategoryButton(self, event):
        self.refresh_list('category')

    def OnBtnSupplierButton(self, event):
        self.refresh_list('supplier')
